
// import {getTeamWorksData} from "@/api/modules/task.js"

import { defineStore } from "pinia"
import { getStaffData, staffRegister, getPowerList, setStaffIdentity,getOwnteamMember } from "@/api/modules/staff.js"
import { ElMessage, ElLoading } from 'element-plus'

import { dateConversion } from "@/utils/util"
export const staffData = defineStore("staffData", {
    state: () => {
        return {
            staffInfo: [],

            formStaffColumnData: {},
            chargemanList: [],
            staffData:{},
            pageTotalSize:0,
            wei:0,
            ownTeamMember:[]
        }
    },
    actions: {
        // 获取员工数据
        async getStaff(data) {
            // console.log(data,"fefes")
            const loading = ElLoading.service({
                lock: true,
                text: 'Loading',
                background: 'rgba(0, 0, 0, 0.7)',
            })
            let res = await getStaffData(data)
            try{
                if (res.code == 200) {

                    // console.log(res,"这是什么数据啊")
                    res.data.forEach(item => {
                        item.registerTime = item.registerTime ? dateConversion(item.registerTime) : ""
                        if (item.identity) {
                            item.identity.idenCreateTime = dateConversion(item.identity.idenCreateTime)
                        }
    
                    })
                    this.staffInfo = res.data
                    this.pageTotalSize = res.count
                    return "ok"
                } else {
                    return "faile"
                }
            }finally{
                setTimeout(() => {
                    loading.close()
                }, 1000);
            }

        },

        //员工注册
        async getStaffRegisterData(data) {
            // console.log(data,"我是仓库里面的数据")
            let res = await staffRegister(data)
            // console.log(res,'fesfes')
            if (res.code == 200) {
                return res
            } else {
                return res
            }
        },

        // 获取组长数据
        async getPowerListData() {

            let res = await getPowerList()

            // console.log(res.data)
            this.chargemanList = res.data

        },

        // 设置员工的职位

        async setStaffIden(data) {
            const loading = ElLoading.service({
                lock: true,
                text: 'Loading',
                background: 'rgba(0, 0, 0, 0.7)',
            })
            // console.log(data, "我是仓库里面的")
            try {
                let res = await setStaffIdentity(data)
                // console.log(res)
                if (res.code == 200) {
                    ElMessage({
                        message: '员工职位设置成功',
                        type: 'success',
                    })
                    return "ok"
                } else {
                    ElMessage({
                        message: '员工职位设置失败',
                        type: 'error',
                    })
                    return "false"
                }
            } finally {
                setTimeout(() => {
                    loading.close()
                }, 1000);
            }
        },

        async getOwnteamMemberData(data){
            // console.log(data)
            let res = await getOwnteamMember(data)
            this.ownTeamMember = res.data
            // console.log(res,"获取数据了吗")
        }

       
    },
    getters: {

    },
    persist:{
        storage:localStorage,
        paths:["wei"]
    }
})

